<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript">
$(document).ready(function(){
	$(".cls").datepicker({
		dateFormat:"yy-mm-dd",changeYear:true,changeMonth:true,maxDate:"0y 0m",minDate:"-60y",
		monthNamesShort:["1월", "2월", "3월", "4월", "5월", "6월","7월", "8월", "9월", "10월", "11월", "12월"],
		showButtonPanel:true,closeText:"닫기",
		dayNamesMin:[ "일", "월", "화", "수", "목", "금", "토" ]});
});

function getBusinessRecord(){

	if($("#disposalSort").val()=='구분'){
		alert("처리자 구분은 필수 사항입니다.");
		$("#disposalSort").focus();
		return false;
	}
	if(($("#sort").val()=='전체')){
		alert("업무 구분은 필수 사항입니다.");
		$("#sort").focus();
		return false;
	}
	if(($("#sort2").val()=='상세구분을 선택하세요')){
		alert("업무 구분은 필수 사항입니다.");
		$("#sort2").focus();
		return false;
	}
	if($("#startDate").val()==''){
		alert("기간 설정은 필수 사항입니다.");
		$("#startDate").focus();
		return false;
	}
	if($("#endDate").val()==''){
		alert("기간 설정은 필수 사항입니다.");
		$("#endDate").focus();
		return false;
	}
	if($("#content").val()==''){
		alert("내용을 입력해주세요");
		$("#content").focus();
		return false;
	}
}

function getBusinessSort(){
	var sort = $("#sort").val();
	$.ajax({
		"url":"/${initParam.context_root}/myshop/getBusinessSort.do",		//요청 URL설정
		type:"POST",																								//요청 방식 - 생략하면 GET
		data:{firstSort:sort},																					//요청파라미터 1.queryString, 2. JS 객체
		dataType:"JSON",																						//응답데이터의 형태(Default : text)														//에러응답이 온경우 호출할 함수 등록
		success:function(JSON){																			//정상 응답이 온 경우 호출할 함수 등록
			//success등록 함수 매개변수(모두 생략가능)
			//1. 서버가 응답한 데이터, 2. 응답 코드 메세지(success,error), 3.XHR
			$("#sort2").html("<option>상세구분을 선택하세요</option>");
			
			for(var idx=0; idx<JSON.list.length;idx++){
				$("#sort2").append("<option>"+JSON.list[idx]+"</option>");
			}
		}
		//beforeSend:checkId
	});
}
</script>
<style type="text/css">
 	
  	.headline {margin-top: 0px; margin-bottom: 10px; margin-right: auto;}
  	.headtext {font-weight: bolder; color:#B061BF; margin-top: 20px; margin-bottom: 0px; font-style: 돋음; }
</style>
<h2 class="headtext">업무 관리</h2>
<hr class="headline">
<form id="businessRecordForm" action="/${initParam.context_root }/myshop/getBusinessRecord.do" onsubmit="return getBusinessRecord()">
<table>
	<tr>
		<td>업무 구분</td>
		<td><select id="sort" name="sort" onchange="getBusinessSort()"><option>전체</option><option>관리자</option><option>회원</option><option>상점</option><option>주문</option>
												<option>상품</option><option>게시판</option><option>운영자</option><option>거래처</option>
												<option>다운로드</option><option>고객혜택</option><option>기타</option></select>
				<select id="sort2" name="sort2" ><option>전체</option></select></td>
	</tr>
	<tr>
		<td>기간</td><td>시작 <input type="text" name="startDate" id="startDate" class="cls"> ~ 종료 <input type="text" name="endDate" id="endDate" class="cls"></td>
	</tr>
	<tr>
		<td colspan='2' align="center"><input type="submit" value="search"></td>
	</tr>
</table>
</form>

<h3 class="headtext">업무처리목록</h3>
<hr class="headline">
<table class="table table-bordered"  align="center" width="500" border='1' cellspacing="0">
		<thead>
			<tr align="center" style="background-color:#453949; color: white;">
				<td>NO</td><td>구분</td><td>상세구분</td><td>처리일시</td><td>처리자 구분</td>
			</tr>
		</thead>
		
		<tbody>
			<c:forEach items="${requestScope.businessRecord_list }" var="businessRecord">
					<tr><td>${businessRecord.businessNo }</td><td>${businessRecord.sort }</td>
					<td>${businessRecord.sort2 }</td><td>${businessRecord.disposalDate }</td><td>${businessRecord.disposer }</td></tr>
			</c:forEach>
		</tbody>
			<tr>
				<td colspan="5" align="center">
					<p>
							<c:choose>
							<c:when test="${requestScope.paging.previousPageGroup }">
								<a href="/${initParam.context_root }/myshop/getBusinessRecord.do?page=${requestScope.paging.startPageOfPageGroup-1}&sort=${requestScope.sort }&sort2=${requestScope.sort2 }&startDate=${requestScope.startDate }&endDate=${requestScope.endDate }">☜</a>
							</c:when>
								<c:otherwise>☜</c:otherwise>
							</c:choose>
						<c:forEach begin="${requestScope.paging.startPageOfPageGroup }" end="${requestScope.paging.endPageOfPageGroup }" var="page">
							<c:choose>
								<c:when test="${page==requestScope.currentPage }">
									[${page }]
								</c:when>
								<c:otherwise>
									<a href="/${initParam.context_root }/myshop/getBusinessRecord.do?page=${page }&sort=${requestScope.sort }&sort2=${requestScope.sort2 }&startDate=${requestScope.startDate }&endDate=${requestScope.endDate }">${page }</a>
								</c:otherwise>
							</c:choose>
						</c:forEach>
							<c:choose>
							<c:when test="${requestScope.paging.nextPageGroup }">
								<a href="/${initParam.context_root }/myshop/getBusinessRecord.do?page=${requestScope.paging.endPageOfPageGroup+1}&sort=${requestScope.sort }&sort2=${requestScope.sort2 }&startDate=${requestScope.startDate }&endDate=${requestScope.endDate }">☞</a>
								</c:when>
							<c:otherwise>☞</c:otherwise>
						</c:choose>
				</td>
			</tr>
			<tr>
				<td colspan="5" align="center">
					<button> <a href="/${initParam.context_root }/myshop/businessRecordView.do">엑셀다운로드</a></button>
				</td>
			</tr>
	</table>
	<div>
	<h3 align="center"><font color="red">등록 및 변경 후 업데이트 된 정보를 보시려면 'F5'key를 눌러주세요~!</font></h3>
	</div>


